package structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: Composite
 * @Description: 树枝节点（BranchNode）
 * @Author: liu-hao
 * @Date: 2023-04-09 17:51
 * @Version: 1.0
 **/
public class Composite implements Component {

    private List<Component> children = new ArrayList<Component>();

    @Override
    public void add(Component c) {
        children.add(c);
    }

    @Override
    public void remove(Component c) {
        children.remove(c);
    }

    @Override
    public List<Component> getChildren() {
        return children;
    }

    @Override
    public void operation() {
        for (Object obj : children) {
            ((Component) obj).operation();
        }
    }
}
